﻿using ML.IBusiness;
using System.Web.Mvc;
using System.Threading.Tasks;
using ML.Entity;

namespace ML.Web.Controllers
{
    /// <summary>
    /// 系统首页控制器
    /// </summary>
    public class LoginController : BaseController
    {
        private IUserBusiness userBusiness;
        public LoginController(IUserBusiness _userBusiness)
        {
            userBusiness = _userBusiness;
        }

        /// <summary>
        /// 后台管理登录页面
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 管理员登陆
        /// </summary>
        /// <param name="login_name_in">用户名</param>
        /// <param name="user_pwd_in">密码</param>
        /// <returns></returns>
        [HttpPost]
        [AjaxOnly]
        public ActionResult Login(string login_name_in, string user_pwd_in)
        {
            var data = userBusiness.Login(login_name_in, user_pwd_in);
            return Json(data);
        }

        /// <summary>
        /// 用户修改密码
        /// </summary>
        /// <param name="password_old">老密码</param>
        /// <param name="password_new">新密码</param>
        /// <returns></returns>
        [HttpPost]
        [AjaxOnly]
        public ActionResult UpdatePassword(string id = "", string password_new = "")
        {
            var user_id = id;
            if (string.IsNullOrEmpty(user_id))
            {
                user_id = UserHelper.GetCurrentUserId();
            }
            var data = userBusiness.UpdatePassword(user_id, password_new);
            return Json(data);
        }
    }
}